package service

//API is interface
import (
	"apibe/single/src/v1/factory"
	"apibe/single/src/v1/service/impl"
	"apibe/single/src/v1/share/crypt"
	"errors"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
)

// Service
// UpdateOne 单条数据更新
// UpdateMany 多条数据更新
// UpdateStatus 更新状态
// RemoveIdPhysics 物理删除
// FindOneId 根据id查询
// FindOneFilter 按条件查询(单条)
// FindManyFilter 按条件查询(多条)
// Exist 条件查询是否存在
type Service interface {
	FindOneId(id primitive.ObjectID) *mongo.SingleResult
	FindOneFilter(filter map[string]interface{}) *mongo.SingleResult
	FindManyFilter(filter map[string]interface{}, page int, pageSize int) (*mongo.Cursor, int64, error)
	UpdateOne(filter map[string]interface{}, update map[string]interface{}, claims *crypt.CustomClaims) (*mongo.UpdateResult, error)
	UpdateStatus(id primitive.ObjectID, claims *crypt.CustomClaims, status factory.Status) (*mongo.UpdateResult, error)
	Exist(filter map[string]interface{}) bool

	// RemoveIdPhysics(id primitive.ObjectID, claims *crypt.CustomClaims) (*mongo.DeleteResult, error)
	// UpdateMany(filter interface{}, update map[string]interface{}, claims *crypt.CustomClaims) (*mongo.UpdateResult, error)
}

// Name
// UserService 用户相关接口
// DesignService 接口配置相关接口
type Name uint8

const (
	UserService Name = iota
	DesignService
	TaskService
)

type DB uint8

const (
	Mongodb DB = iota
	Mysql
	Postgresql
)

// NewService
// 简单工厂模式
func NewService(name Name) (Service, error) {
	switch name {
	case UserService:
		return &impl.User{}, nil
	case DesignService:
		return &impl.Design{}, nil
	case TaskService:
		return &impl.Task{}, nil
	default:
		return nil, errors.New(" There is no such service ")
	}
}